package com.lawfinal.controller;


import com.lawfinal.entity.Assistance;
import com.lawfinal.service.AssistanceService;
import com.lawfinal.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 * 法律援助案例 前端控制器
 * </p>
 *
 * @author KBr
 * @since 2024-04-06
 */
@RestController
@CrossOrigin("http://localhost:5173/")
@RequestMapping("/assistance")
public class AssistanceController {

      @Autowired
      private AssistanceService assistanceService;

      @RequestMapping("/select")
      public Result apply(@RequestBody Assistance assistance){
            return assistanceService.save(assistance)?Result.sucess():Result.fail();
      }

      @RequestMapping("findByLawyer")
      public Result findByLawyer( String lawyer){
            List list=assistanceService.lambdaQuery().eq(Assistance::getLawyer,lawyer).list();
            return list.size()>0?Result.sucess(list):Result.fail();
      }

      @RequestMapping("/del")
      public Result deleteById(String id){
            return assistanceService.removeById(id)?Result.sucess():Result.fail();
      }
}
